<template>
	<view class="myWallet p20">
		<view class="walletTop">
			<view class="walletNum">
				<view class="numVal">{{ balance }}</view>
				<view class="numText">可提现余额</view>
			</view>
			<view class="walletList dis">
				<view class="item">
					<view class="itemT">{{ weeklyIncome }}</view>
					<view class="itemB">本周收入</view>
				</view>
				<view class="item">
					<view class="itemT">{{ monthlyIncome }}</view>
					<view class="itemB">本月收入</view>
				</view>
				<view class="item">
					<view class="itemT">{{ totalIncome }}</view>
					<view class="itemB">总收入</view>
				</view>
			</view>
			<view class="embody dis">
				提现
				<up-icon color="#2aad67" name="arrow-right" size="28rpx"></up-icon>
			</view>
		</view>
		<view class="tab dis">
			<view class="tabItem" :class="tabId == 0 ? 'avtive' : ''" @click="changeTab(0)">账单明细</view>
			<view class="tabItem" :class="tabId == 1 ? 'avtive' : ''" @click="changeTab(1)">提现记录</view>
		</view>
		<view class="list" v-if="list.length > 0">
			<template v-if="tabId == 0">
				<view class="item p30 dis" v-for="item in list" :key="item.id">
					<view class="itemL">￥</view>
					<view class="itemR dis">
						<view class="infoL dis">
							<view class="infoTitle">{{ item.billContent }}</view>
							<view class="infoTiem">{{ item.createTime }}</view>
						</view>
						<view class="infoR dis">
							<view class="numT" :class="item.billMoney > 0 ? 'errColor' : 'succeedColor'">{{ item.billMoney > 0 ? `+${item.billMoney}` : item.billMoney }}</view>
							<view class="numB">余额:{{ item.balanceAfter }}</view>
						</view>
					</view>
				</view>
			</template>
			<!-- 提现记录 -->
			<template v-if="tabId == 1">
				<view class="item p30" v-for="item in list" :key="item.id">
					<view class="itemT dis">
						<view class="itemL">￥</view>
						<view class="itemR dis">
							<view class="infoL dis">
								<view class="infoTitle">购物消费</view>
								<view class="infoTiem">{{ item.createTime }}</view>
							</view>
							<view class="infoR dis">
								<view class="dis numT succeedColor">{{ item.withdrawalMoney }}</view>
							</view>
						</view>
					</view>
					<view class="itenB p20">拒绝原因:{{ item.rejectReason }}</view>
					<view class="type" :class="item.withdrawalStatus == 2 ? 'errBut' : 'primaryBut'">{{ item.withdrawalStatus == 2 ? '已拒绝' : '待审核' }}</view>
				</view>
			</template>
			<view class="noData">没有更多内容了，亲~</view>
		</view>
		<view class="noData" v-else>暂无数据</view>
	</view>
</template>

<script setup>
import { getUserRevenue, getUserBill, getUserRecord } from '@/config/api.js';
import { ref, reactive } from 'vue';
import { onShow, onLoad, onReachBottom } from '@dcloudio/uni-app';
onLoad((options) => {
	getUserRevenueFun();
	initList();
});
onShow(() => {});
const balance = ref('0.00');
const weeklyIncome = ref('0.00');
const monthlyIncome = ref('0.00');
const totalIncome = ref('0.00');
const getUserRevenueFun = async () => {
	const res = await getUserRevenue();
	// console.log(res);
	if (res.code == 0) {
		balance.value = res.data.balance;
		if (res.data.userRevenue != null) {
			weeklyIncome.value = res.data.userRevenue.weeklyIncome;
			monthlyIncome.value = res.data.userRevenue.monthlyIncome;
			totalIncome.value = res.data.userRevenue.totalIncome;
		}
	}
};

const pageNum = ref(1);
const pageSize = ref(20);
const total = ref(0);
const list = ref([]);
const initList = () => {
	pageNum.value = 1;
	total.value = 0;
	list.value = [];
	getList();
};
const getList = async () => {
	if (tabId.value == 0) {
		const res = await getUserBill();
		// console.log(res);
		if (res.code == 0) {
			total.value = res.data.pageInfo.total;
			list.value = res.data.pageInfo.list;
		}
	} else {
		const res = await getUserRecord();
		// console.log(res);
		if (res.code == 0) {
			total.value = res.data.pageInfo.total;
			list.value = res.data.pageInfo.list;
		}
	}
};

const tabId = ref(0);
const changeTab = (val) => {
	tabId.value = val;
	initList();
};
onReachBottom(() => {
	// console.log('触底加载');
	if (list.value.length >= total.value) {
		console.log('没有更多内容了');
	} else {
		pageNum.value++;
		getList();
	}
});
</script>

<style scoped lang="scss">
.myWallet {
	.walletTop {
		position: relative;
		color: #fff;
		background-color: #2aad67;
		border-radius: 10rpx;
		.walletNum {
			padding-top: 50rpx;
			width: 100%;
			text-align: center;
			.numVal {
				margin-bottom: 10rpx;
				font-size: 45rpx;
				font-weight: 700;
			}
		}
		.walletList {
			padding: 0 54rpx;
			padding-top: 25rpx;
			padding-bottom: 30rpx;
			width: 100%;
			.item {
				padding-bottom: 15rpx;
				width: 200rpx;
				text-align: center;
				border-left: 1rpx solid #fff;
				.itemT {
					margin-bottom: 20rpx;
				}
			}
			.item:first-child {
				border-left: none;
			}
		}
		.embody {
			position: absolute;
			top: 20rpx;
			right: 0;
			padding: 5rpx 25rpx;
			line-height: 40rpx;
			font-size: 28rpx;
			color: #2aad67;
			border-radius: 25rpx 0 0 25rpx;
			background-color: #fff;
		}
	}
	.tab {
		justify-content: space-around;
		align-items: center;
		margin-top: 20rpx;
		height: 90rpx;
		font-size: 28rpx;
		color: #646566;
		background-color: #fff;
		.tabItem {
			height: 100%;
			line-height: 90rpx;
		}
		.avtive {
			position: relative;
			font-size: 33rpx;
			color: #000;
			font-weight: 700;
		}
		.avtive::after {
			position: absolute;
			left: 50%;
			bottom: 0;
			content: '';
			width: 40rpx;
			height: 5rpx;
			border-radius: 3rpx;
			background-color: #2aad67;
			transform: translateX(-50%);
		}
	}
	.list {
		margin-top: 20rpx;
		.item {
			position: relative;
			background: #fff;
			border-bottom: 2rpx solid #ddd;
			overflow: hidden;
			.itemL {
				margin-right: 20rpx;
				width: 80rpx;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				font-size: 45rpx;
				border-radius: 50%;
				color: #fff;
				background-color: #ffd700;
			}
			.itemR {
				flex: 1;
				.infoL {
					flex: 1;
					flex-direction: column;
					justify-content: space-between;
					align-items: flex-start;
					.infoTitle {
						font-size: 28rpx;
					}
					.infoTiem {
						font-size: 24rpx;
						color: #888;
					}
				}
				.infoR {
					flex-direction: column;
					justify-content: space-between;
					align-items: flex-end;
					width: 200rpx;
					.numT {
						font-size: 30rpx;
					}
					.numB {
						font-size: 24rpx;
						color: #888;
					}
				}
			}
			.itenB {
				margin-top: 30rpx;
				border-top: 2rpx solid #ddd;
				font-size: 30rpx;
			}
			.itemT {
				.itemR {
					.infoR {
						.numT {
							justify-content: space-between;
							align-items: center;
							height: 100%;
							text-align: right;
						}
					}
				}
			}
			.type {
				position: absolute;
				left: 0rpx;
				top: 0rpx;
				padding: 5rpx 0;
				width: 400rpx;
				font-size: 28rpx;
				text-align: center;
				transform: rotate(-45deg) translate(-30%, -99rpx);
				// background: #fb5050;
				// color: #fff;
			}
		}
		.item:last-child {
			border-bottom: none;
		}
	}
}
.noData {
	width: 100%;
	line-height: 80rpx;
	color: #999;
	text-align: center;
}
</style>

<style>
page {
	background-color: #f7f7f7;
}
</style>
